<!--
 * @Descripttion: (公告/tb_notice 添加弹窗)
 * @version: (1.0)
 * @Author: (lwh)
 * @Date: (2023-10-09)
 * @LastEditors: (lwh)
 * @LastEditTime: (2023-10-09)
-->
<template>
  <el-dialog v-model="props.modelValue" title="添加公告信息" width="900px" @closed="closeDialog" @open="openDialog">
    <el-form ref="formRef" :model="formData" :rules="rules">
      <el-row :gutter="20">


        <el-col :lg="24">
          <el-form-item :label-width="labelWidth" label="标题" prop="noticeTitle">
            <el-input v-model="formData.noticeTitle" placeholder="请输入标题" />
          </el-form-item>
        </el-col>
        <el-col :lg="12">
          <el-form-item :label-width="labelWidth" label="下拉框" prop="noticeContent">
            <el-select v-model="formData.bannerPosition" placeholder="请选择位置">
              <el-option v-for="item in  banner_position " :key="item.dictValue" :label="item.dictLabel"
                :value="parseInt(item.dictValue)"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :lg="24">
          <el-form-item :label-width="labelWidth" label="图片" prop="noticeContent">
            <UploadImage ref="uploadRef" v-model="formData.bannerImg" :data=imgData :limit="1" :fileSize="5"
              :drag="true" />
          </el-form-item>
        </el-col>
        <el-col :lg="12">
          <el-form-item :label-width="labelWidth" label="最后登录时间" prop="customerLastLoginTime">
            <el-date-picker v-model="formData.customerLastLoginTime" type="datetime" :teleported="false"
              placeholder="选择日期时间"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :lg="24">
          <el-form-item :label-width="labelWidth" label="工作时间" prop="">
            <el-time-picker v-model="dateRange" style="width: 240px" is-range format='HH:mm' value-format='HH:mm'
              range-separator="-" start-placeholder="上班时间" end-placeholder="下班时间">
            </el-time-picker>
          </el-form-item>
        </el-col>
        <el-col :lg="12">
          <el-form-item :label-width="labelWidth + 20" label="库存计算方式" prop="goodsDeductStockType">
            <el-radio-group v-model="formData.goodsDeductStockType">
              <el-radio :label="1">选项1</el-radio>
              <el-radio :label="2">选项2</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :lg="24">
          <el-form-item :label-width="labelWidth" label="内容" prop="noticeContent">
            <el-input v-model="formData.noticeContent" type="textarea" :rows="5" placeholder="请输入内容" />
          </el-form-item>
        </el-col>
        <el-col :lg="12">
          <el-form-item :label-width="labelWidth" label="排序" prop="noticeSort">
            <el-input-number v-model.number="formData.noticeSort" controls-position="right" :min="0" />
          </el-form-item>
        </el-col>

      </el-row>
    </el-form>

    <template #footer>
      <div key="dialog-footer">
        <el-button type="primary" @click="handleAddClick(formRef)" :loading="loadingStatus">添加</el-button>
        <el-button @click="handleResetClick(formRef)">重置</el-button>
      </div>
    </template>
  </el-dialog>
</template>


<script setup>
import { reactive, ref, watch } from "vue";
import { ElMessage } from 'element-plus'
// import { addOrUpdateNotice } from '@/api/business/Advertisement/Notices/notice.js';


// 打开弹窗时回调
const openDialog = async () => {


}

// -业务参数
let banner_position = ref([
  {
    dictLabel: "下拉框数据1",
    dictValue: 1,
  },
  {
    dictLabel: "下拉框数据2",
    dictValue: 2,
  },
])

// -业务方法



// -基础参数
const loadingStatus = ref(false)
const labelWidth = 100;
const formRef = ref();
const emits = defineEmits(["update:modelValue"]);
const formData = reactive({
  noticeSort: 1
});
const props = defineProps({
  modelValue: Boolean,
  done: Function,
});
const imgData = ref({
  fileDir: "Notice"
})

// 验证
const rules = reactive({
  noticeGuid: [{ required: true, message: "不能为空", trigger: "blur", type: "number" }],
  noticeTitle: [{ required: true, message: "标题不能为空", trigger: "blur" }],
  noticeContent: [{ required: true, message: "内容不能为空", trigger: "blur" }],
  noticeSort: [{ required: true, message: "排序不能为空", trigger: "blur", type: "number" }],
});

// -基础方法

// 提交
const handleAddClick = async (formEl) => {
  if (!formEl) return;
  formEl.validate(async (valid) => {
    if (!valid) {
      return;
    }
    loadingStatus.value = true


    // const { code } = await addOrUpdateNotice(formData);
    // if (code == 200) {
    //   ElMessage({
    //     message: '添加成功',
    //     type: 'success',
    //   })
    //   closeDialog();
    //   loadingStatus.value = false
    // }
  });
};
const closeDialog = () => {
  handleResetClick(formRef.value);
  props.done();
  emits("update:modelValue", false);
};
const handleResetClick = async (formEl) => {
  if (!formEl) return;
  formEl.resetFields();
};
</script>